package com.atguigu.distributed.lock.mapper;

import com.atguigu.distributed.lock.pojo.*;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author linjy on 2022/9/18
 */
@Service
public interface StockMapper extends BaseMapper<Stock> {
    @Update("update tb_stock set count = count - #{count} where product_code = #{productCode} and id =#{id} and count >=#{count}")
    int updateStock(@Param("productCode") String productCode, @Param("count") Integer count, @Param("id") Integer id);

    @Select("select * from tb_stock where product_code =#{productCode} for update")
    List<Stock> queryStock(String productCode);
}